<!-- 分配专员 -->
<template>
  <a-modal :maskClosable="false" centered :width="500" v-model="visible" @ok="handleSubmit">
    <template slot="title">
      <span>分配服务专员</span>
      <span class="fz-14 _pl-10" style="color:#1890ff;">
        已选用户 ({{ form.memberIds ? form.memberIds.length : 0 }}人)
      </span>
    </template>
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 12 }">
      <a-form-model-item label="选择服务专员" prop="sysUserId">
        <a-select v-model="form.sysUserId" allowClear>
          <a-select-option v-for="item in attacheList" :key="item.id">{{ item.userName }}</a-select-option>
        </a-select>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import { editCurrentService } from '@/api/member/member'
export default {
  props: ['attacheList'],
  components: {},
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      title: '分配服务专员',
      visible: false,
      form: {
        memberId: undefined,
        sysUserId: undefined
      },
      // rules: {
      //   sysUserId: [{ required: true, message: '请选择服务专员', trigger: 'change' }]
      // }
    }
  },
  computed: {},
  watch: {},
  methods: {
    show(row) {
      this.title = row.attacheUserId ? '编辑服务专员' : '分配服务专员'
      if (row.memberIds) {
        this.title = '批量分配服务专员'
      }

      this.visible = true
      this.$nextTick(() => {
        this.$refs.ruleForm.resetFields()
        this.form.memberId = row.id
        this.form.memberIds = row.memberIds
        let existIndex = this.attacheList.findIndex(v => v.id === row.attacheUserId)
        this.form.sysUserId = existIndex === -1 ? undefined : row.attacheUserId
        this.$forceUpdate()
      })
    },
    async handleSubmit() {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          let { code, msg } = await editCurrentService({ ...this.form })
          this.$message[code === 0 ? 'success' : 'error'](msg)
          if (code === 0) {
            this.$emit('success')
            this.visible = false
          }
        }
      })
    }
  },
  created() {},
  mounted() {}
}
</script>
<style scoped></style>
